<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="税务局代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxName">
               <j-dict-select-tag type="list" v-model="model.taxName" v-bind:dictCode="taxbind" placeholder="请选择所属税务机关" />               
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加油站名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stationName">
              <a-input v-model="model.stationName" placeholder="请输入纳税人名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加油站类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="stationCate">
              <j-dict-select-tag type="list" v-model="model.stationCate" dictCode="station_cat" placeholder="请选择加油站类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="统一社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unioncode">
              <a-input v-model="model.unioncode" placeholder="请输入统一社会信用代码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="加油机数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="machinecount">
              <a-input-number v-model="model.machinecount" placeholder="请输入加油机数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tel">
              <a-input v-model="model.tel" placeholder="请输入电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="从业人数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="staffCount">
              <a-input-number v-model="model.staffCount" placeholder="请输入从业人数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经营地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="address">
              <a-input v-model="model.address" placeholder="请输入经营地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开业时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="openDate">
              <j-date placeholder="请选择开业时间" v-model="model.openDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="办税员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taxOpName">
              <a-input v-model="model.taxOpName" placeholder="请输入办税员"  ></a-input>
            </a-form-model-item>
          </a-col>          
          <a-col :span="24">
            <a-form-model-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longitude">
              <a-input v-model="model.longitude" placeholder="请输入经度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latitude">
              <a-input v-model="model.latitude" placeholder="请输入纬度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col v-if="showFlowSubmitButton" :span="24" style="text-align: center">
            <a-button @click="submitForm">提 交</a-button>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
  import Vue from 'vue'
  import { USER_INFO } from "@/store/mutation-types"
  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'StationForm',
    components: {
    },
    props: {
      //流程表单data
      formData: {
        type: Object,
        default: ()=>{},
        required: false
      },
      //表单模式：true流程表单 false普通表单
      formBpm: {
        type: Boolean,
        default: false,
        required: false
      },
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/station/station/add",
          edit: "/station/station/edit",
          queryById: "/station/station/queryById"
        },
        taxbind:"sys_depart,depart_name,org_code"
      }
    },
    computed: {
      formDisabled(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return false
          }
          return true
        }
        return this.disabled
      },
      showFlowSubmitButton(){
        if(this.formBpm===true){
          if(this.formData.disabled===false){
            return true
          }
        }
        return false
      }
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
      //如果是流程中表单，则需要加载流程表单data
      this.showFlowData();
       //alert("sss");
      
     
    },
    methods: {
      add () {
        let user = Vue.ls.get(USER_INFO);
      this.modelDefault.taxName=user.orgCode;
      window.console.log("yaochuan here:"+user.orgCode);
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
       
        this.visible = true;
      },
      //渲染流程表单数据
      showFlowData(){
        if(this.formBpm === true){
          let params = {id:this.formData.dataId};
          getAction(this.url.queryById,params).then((res)=>{
            if(res.success){
              this.edit (res.result);
            }
          });
        }
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>